<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./TemplatePrincipal.xhtml">

            <ui:define name="top">
                <p:panel>
                    <p:clock mode="server" autoSync="true" pattern="HH:mm:ss dd/MM/yy" />
                </p:panel>
            </ui:define>

            <ui:define name="left">
                <p:panel>
                    <h:form>
                        <p:commandButton ajax="false" id ="newUserButton" value="New" action="UserCreateEdit" actionListener="#{userBean.prepareNew}">
                            <p:tooltip for="newUserButton" value="Add new User..."/>
                        </p:commandButton>
                        <p:commandButton ajax="false" id ="backMenuButton" value="Back" action="PrincipalMenu">
                            <p:tooltip for="backMenuButton" value="Back to main menu..."/>
                        </p:commandButton>
                    </h:form>
                </p:panel>

            </ui:define>

            <ui:define name="content">
                <f:view>
                    <h:form id="formUser">
                        <p:panel>
                            <p:dataTable value="#{userBean.userList}" var="item">
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Name"/>
                                    </f:facet>
                                    <h:outputText value="#{item.name}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="First name"/>
                                    </f:facet>
                                    <h:outputText value="#{item.firstname}"/>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Delete"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton value="Delete" 
                                                         action="UserConfirm" 
                                                         actionListener="#{userBean.prepareRemove}"
                                                         id="deleteUButton" ajax="false"/>
                                        <p:tooltip for="deleteUButton" value="Delete selected user..."/>
                                    </center>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <p:outputLabel value="Edit"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton value="Edit" action="UserCreateEdit" 
                                                         actionListener="#{userBean.prepareEdit}"
                                                         id="editUButton" ajax="false">
                                            <p:tooltip for="editUButton" value="Edit selected user..."/>
                                            <f:setPropertyActionListener value="#{item}" target="#{userBean.user}"/>
                                        </p:commandButton>
                                    </center>
                                </p:column>
                                <p:column>
                                    <f:facet name="header">
                                        <h:outputText value="Details"/>
                                    </f:facet>
                                    <center>
                                        <p:commandButton 
                                            value="See ID" 
                                            update=":formUser:panelUser" 
                                            onclick="dialogUser.show();" 
                                            icon="ui-icon-info" 
                                            id="seeUButton">
                                            <p:tooltip for="seeUButton" value="See more of selected User..."/>
                                            <f:setPropertyActionListener value="#{item}" target="#{userBean.user}"/>
                                        </p:commandButton>
                                    </center>
                                </p:column>                            
                            </p:dataTable>
                            <p:dialog widgetVar="dialogUser" modal="true" width="250" 
                                  height="200" showEffect="fade" hideEffect="explode" 
                                  resizable="false" position="600 ,150" draggable="false">
                            <h1><h:outputText value="User details..."/></h1>
                            <h:panelGrid columns="2" id="panelUser">
                                <h:outputText value="Id: "/>
                                <h:outputText value="#{userBean.user.id}" title="Id"/>
                                <h:outputText value="Last name: "/>
                                <h:outputText value="#{userBean.user.lastname}" title="Lastname"/>
                                <h:outputText value="Acces Id: "/>
                                <h:outputText value="#{userBean.user.accesId}" title="AccesId"/>
                                <h:outputText value="Password: "/>
                                <h:outputText value="#{userBean.user.password}" title="Password"/>
                            </h:panelGrid>
                        </p:dialog>
                        </p:panel>
                    </h:form>
                </f:view>
            </ui:define>
        </ui:composition>

    </body>
</html>
